<?php

//包含头部文件
include './head.php';


//接收get传值 ,获取版块cid, 是否精华elite 和 当前页数page, 
$getCid   = $_GET['cid'];
$getElite = isset($_GET['elite']) ? $_GET['elite'] : '';
$currPage = isset($_GET['page'])?$_GET['page']:1;
//var_dump($getCid);
//var_dump($getElite);
//var_dump($currPage);


//查询数据库
//查询出该版块的所有帖子信息
$resGet = mySelect($link , '*' , DB_TABLE_DETAIL , "where classid = $getCid and first = 1  and isdel=0  order by addtime   desc");
//var_dump($resGet);

//通过cid 查出当前的版块名,及其父版块名
$resCategory = mySelect($link , '*' , DB_TABLE_CG ,"where cid=$getCid");
$parentId  = $resCategory[0]['parentid'];
$sonName  = $resCategory[0]['classname'];
//查询父级版块
$resParent = mySelect($link , '*' , DB_TABLE_CG ,"where cid=$parentId");
$parentName  = $resParent[0]['classname'];
// var_dump($resCategory);
// var_dump($parentId);
// var_dump($resParent);


//遍历出所有版块信息
$resPub = mySelect($link, '*' , DB_TABLE_CG , "where cisdel=0");
//var_dump($resPub);

//遍历出所有的用户信息
$resPubUser = mySelect($link , '*' , DB_TABLE_USER , "where uisdel=0"); 
//var_dump($resPubUser);


//获取当天凌晨的时间戳
//var_dump(date('Y-m-d H:i:s'));
$zeroTime = (strtotime(date('Y-m-d') , time()));
// $zeroTime2 = date('Y-m-d H:i:s' , $zeroTime);
// var_dump($zeroTime);
// var_dump($zeroTime2);

//计算当日发表的帖子条数
$todayCount = myCount($link , 'id' , DB_TABLE_DETAIL , "where first = 1  and  classid = $getCid   and    addtime > $zeroTime "); 
// var_dump($todayCount);

//获取当前版块所有 精华帖
/*
$resElite = mySelect($link , '*' , DB_TABLE_DETAIL , "where classid = $getCid and first = 1 and elite=1 order by addtime desc");
var_dump($resElite);
*/

//分页
$resPage = myPage($link ,  8 , 'id', DB_TABLE_DETAIL , "where classid = $getCid and first = 1  and isdel=0  order by  istop desc,addtime desc");
//var_dump($resPage);

//解开数组,取出分页参数
if ($resPage) {

	extract($resPage);
	
}/* else {
	
	echo '该版块暂无帖子';
}*/
//判断当前页面是否超出范围
if ($currPage > $total) {
	$currPage = $total;
}
if ($currPage < 1) {
	$currPage = 1;
}

/*
var_dump($rows);
var_dump($prev);
var_dump($next);
var_dump($total);
 var_dump($offset);
var_dump($num);
*/

//打包数组
$arr = compact('webSite', 'docRoot'  ,'sonName' , 'parentName', 'resPub' , 'getCid' , 'getElite' , 'resGet' , 'resPubUser' ,'currPage' , 'resPage' , 'rows','count','total', 'num' , 'offset' ,'prev' ,'next' , 'todayCount');
//发送
display('public.html' , $arr);

//包含尾部文件
include  './tail.php';